package models;

import entities.ProductStatus;
import entities.ProductsEntity;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

public class ProductModel {
    private int id;
    private String name;
    private String description;
    private byte type;
    private Date dateEnd;
    private float price;
    private byte status;

    private List<BidInfo> bids;
    private boolean bidAvailable;
    private float minBid;

    public ProductModel() {
    }

    public ProductModel(ProductsEntity entity) {
        this.id = entity.getId();
        this.name = entity.getName();
        this.type = entity.getType();
        this.dateEnd = entity.getDateEnd();
        this.description = entity.getDescription();
        this.price = entity.getMinPrice();
        this.status = entity.getStatus();
    }

    public ProductsEntity generateEntity(){
        ProductsEntity entity = new ProductsEntity();
        entity.setId(id);
        if(dateEnd != null){
            entity.setDateEnd(new Timestamp(dateEnd.getTime()));
        }
        entity.setStatus(ProductStatus.NORMAL);
        entity.setType(type);
        entity.setDescription(description);
        entity.setName(name);
        entity.setMinPrice(price);

        return entity;
    }

    public boolean isExpired(){
        return dateEnd != null && dateEnd.before(new Date());
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public byte getType() {
        return type;
    }

    public void setType(byte type) {
        this.type = type;
    }

    public List<BidInfo> getBids() {
        return bids;
    }

    public void setBids(List<BidInfo> bids) {
        this.bids = bids;
    }

    public boolean getBidAvailable() {
        return bidAvailable;
    }

    public void setBidAvailable(boolean bidAvailable) {
        this.bidAvailable = bidAvailable;
    }

    public float getMinBid() {
        return minBid;
    }

    public void setMinBid(float minBid) {
        this.minBid = minBid;
    }

    public Date getDateEnd() {
        return dateEnd;
    }

    public void setDateEnd(Date dateEnd) {
        this.dateEnd = dateEnd;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public float getPrice() {
        return price;
    }

    public void setPrice(float price) {
        this.price = price;
    }
}
